# -*- coding: utf-8 -*-
"""
# @File    : utils.py
# @Author  : tyl
"""


def find_dup_ref(ref: str):
    """
    查找参考文献中是否存在重复引用的情况
    :param ref: 参考文献
    :return:
    """
    refs = ref.split('\n')
    citations = []
    for ref in refs:
        citation = ref.split(" ", 1)[-1]
        citations.append(citation)
    unique_citations = set(citations)
    if len(unique_citations) != len(citations):
        print("\n参考文献中存在重复引文!")
        duplicate_citations = []
        seen = set()
        for citation in citations:
            if citation in seen:
                duplicate_citations.append(citation)
            else:
                seen.add(citation)
        print("重复的引文：")
        for key, citation in enumerate(duplicate_citations):
            print(f"{key + 1}. {citation}")
    else:
        print("\n参考文献中不存在重复引文。")


